﻿Imports PTIC_Util
Imports PTIC_GestionBDD
Imports Actuariat
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Windows.Data
Imports System.Windows.Input
Imports OMANE.Common.UI
Imports Microsoft.Practices.Prism.Commands


Namespace ViewModels

    ''' <summary>
    ''' ViewModel de l'écran de paramétrage du choix du fichier d'encours
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ViewModelCmdEncoursImport
        Inherits ViewModelCommand
        Implements IViewModelTabSection

#Region "Variables privées"
        Private m_model As ModelTauxGarantis
        Private _cmdParcourir As ICommand
        Private _cmdVisualiser As ICommand
#End Region

#Region "Constructeur"
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New(ByVal Model As ModelTauxGarantis, ByVal DisplayName As String, ByVal Command As ICommand)
            MyBase.New(DisplayName, Command)
            m_model = Model
        End Sub
        Public Sub New()
        End Sub
#End Region

#Region "Propriétés"
        Public Property IsClosable As Boolean Implements IViewModelTabSection.IsClosable
        Public Property Icone As String Implements Common.UI.IViewModelTabSection.Icone
        Public Property Title As String Implements Common.UI.IViewModelTabSection.Title
        Private ReadOnly Property Model As ModelTauxGarantis
            Get
                Return m_model
            End Get
        End Property

        ''' <summary>
        ''' Traitement d'import de la table d'encours
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property TraitementImportEncours As tableBDD
            Get
                Return Model.ListeTraitements.TraitTbleEncours
            End Get
        End Property
#End Region

#Region "Commandes"

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Property cmdParcourir() As ICommand
            Get
                If _cmdParcourir Is Nothing Then
                    createCmd()
                End If
                Return _cmdParcourir
            End Get
            Private Set(ByVal value As ICommand)
                _cmdParcourir = value
            End Set
        End Property
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Property cmdVisualiser() As ICommand
            Get
                If _cmdVisualiser Is Nothing Then
                    createCmd()
                End If
                Return _cmdVisualiser
            End Get
            Private Set(ByVal value As ICommand)
                _cmdVisualiser = value
            End Set
        End Property

        Private _cmdReinitialiser As ICommand
        Public Property cmdReinitialiser As ICommand
            Get
                If _cmdReinitialiser Is Nothing Then
                    createCmd()
                End If
                Return _cmdReinitialiser
            End Get
            Set(ByVal value As ICommand)
                _cmdReinitialiser = value
            End Set
        End Property

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Sub cmdParcourirExecute()
            Dim openFileDialog1 As New Microsoft.Win32.OpenFileDialog
            openFileDialog1.InitialDirectory = csteEmplacementDefautTbleEncours
            openFileDialog1.DefaultExt = ".sas7bdat"
            openFileDialog1.Filter = "Table SAS (*.sas7bdat)|*.sas7bdat|Fichiers access (*.mdb)|*.mdb"
            If openFileDialog1.ShowDialog() Then
                'On vérifie que l'extenion du fichier est bien .sas7bdat
                'Initilisation du traitement de la table d'encours et de la librairie d'encours SAS
                Dim nomBDDEncours As New Cla_NomFichier(openFileDialog1.FileName)
                Model.Connection.AssignLibName(nomBDDEncours.NomRepertoire, csteLibSASEncours)
                Model.ListeTraitements.TraitTbleEncours.FichierBDD.NomComplet = nomBDDEncours.NomComplet
            End If

        End Sub
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Function cmdParcourirCanExecute() As Boolean
            Return True
        End Function

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Sub cmdVisualiserExecute()
            Dim ui = ModuleTauxGaranti._app.GetService(Of IUIService)()
            Model.ListeTraitements.TraitTbleEncours.Calculer_DataTable()
            Dim tbe As DataTable = Model.ListeTraitements.TraitTbleEncours.DataTableResultat
            ui.ShowMessage(New ViewModelPreviewBase(tbe), _
                           Width:=800, _
                           Height:=600)
        End Sub
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Function cmdVisualiserCanExecute() As Boolean
            Return True
        End Function

        Private Sub cmdReinitialiserExecute()
            Model.Reset()
        End Sub
        Private Function cmdReinitialiserCanExecute() As Boolean
            Return True
        End Function

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Sub createCmd()
            cmdParcourir = New DelegateCommand(AddressOf cmdParcourirExecute, AddressOf cmdParcourirCanExecute)
            cmdVisualiser = New DelegateCommand(AddressOf cmdVisualiserExecute, AddressOf cmdVisualiserCanExecute)
            cmdReinitialiser = New DelegateCommand(AddressOf cmdReinitialiserExecute, AddressOf cmdReinitialiserCanExecute)
        End Sub

#End Region

    End Class

End Namespace